package com.lyw.mine.ui

import android.content.Intent
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import coil.load
import com.alibaba.android.arouter.facade.annotation.Route
import com.hjq.bar.TitleBar
import com.lu.library.base.BaseFragment
import com.lyw.mine.MineRoutePaths
import com.lyw.mine.vm.MineVm
import com.lyw.mine.R
import com.lyw.mine.databinding.FragmentMineBinding
import com.lyw.mine.vm.MineUiState
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
@Route(path= MineRoutePaths.MINE_HOME)
class MineFragment: BaseFragment<FragmentMineBinding>() {

    private val mineViewModel by viewModels<MineVm>();
    override fun initData() {



        lifecycleScope.launch {
            mineViewModel.uiStateFlow.collect{
                when(it){
                    MineUiState.INIT -> {}
                    is MineUiState.UpdateUserInfo -> {
                        binding.tvName.text = it.name
                        binding.ivHead.load(it.head)
                    }
                }
            }
        }

    }

    override fun initListener() {
        super.initListener()
        binding.tvName.setOnClickListener {

            startActivity(Intent(requireActivity(),EditUserInfoActivity::class.java))
        }
    }
    override fun layoutResId(): Int  = R.layout.fragment_mine
}